﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
namespace BYManageInfoSystem
{
    public partial class Frm_DepMonthOutPutRecvAndPay : Form
    {
        private DGBY.BLL.FacFeeTab m_bllFacFeeTab = new DGBY.BLL.FacFeeTab();
        private DGBY.BLL.BYDepartTab m_bllBYDepartTab = new DGBY.BLL.BYDepartTab();
        private DGBY.BLL.FeeTab m_bllFeeTab = new DGBY.BLL.FeeTab();
        private DGBY.BLL.CargoBoxTab m_bllCargoBoxTab = new DGBY.BLL.CargoBoxTab();
        private DGBY.BLL.FacFeeRelationTab m_bllFacFeeRelationTab = new DGBY.BLL.FacFeeRelationTab();
        private DGBY.BLL.FeeInvoiceTab m_bllFeeInvoiceTab = new DGBY.BLL.FeeInvoiceTab();
            
        public Frm_DepMonthOutPutRecvAndPay()
        {
            InitializeComponent();
        }

        public void InitUltraWinGridSetting()
        {
            this.ultraGrid1.DisplayLayout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.True;
            this.ultraGrid1.DisplayLayout.Override.RowSelectorNumberStyle = Infragistics.Win.UltraWinGrid.RowSelectorNumberStyle.VisibleIndex;
            this.ultraGrid1.DisplayLayout.Override.RowSelectorWidth = 40;

        }

        public void LocalPrintPreveiw()
        {
            Infragistics.Shared.ResourceCustomizer rc = Infragistics.Win.Printing.Resources.Customizer;//Resources.Customizer;
            rc.SetCustomizedString("PrintPreview_DialogCaption", "打印预览");
            rc.SetCustomizedString("PrintPreview_Tool_Print", "打印(&P)");
            rc.SetCustomizedString("PrintPreview_Tool_ClosePreview", "关闭(&C)");
            rc.SetCustomizedString("PrintPreview_Tool_ContextMenuPreviewZoom", "显示比例");
            rc.SetCustomizedString("PrintPreview_Tool_Current_Page", "当前页");
            rc.SetCustomizedString("PrintPreview_Tool_Exit", "退出(&X)");
            rc.SetCustomizedString("PrintPreview_Tool_First_Page", "第一页");
            rc.SetCustomizedString("PrintPreview_Tool_Go_To", "跳至");
            rc.SetCustomizedString("PrintPreview_Tool_Last_Page", "最后一页");
            rc.SetCustomizedString("PrintPreview_Tool_Next_Page", "下一页");
            rc.SetCustomizedString("PrintPreview_Tool_Previous_Page", "前一页");
            rc.SetCustomizedString("PrintPreview_Tool_Next_View", "下一视图(&N)");
            rc.SetCustomizedString("PrintPreview_Tool_Previous_View", "前一视图(&P)");
            rc.SetCustomizedString("PrintPreview_Tool_Hand_Tool", "手型工具(&H)");
            rc.SetCustomizedString("PrintPreview_Tool_Page_Setup", "页面设置(&U)");
            rc.SetCustomizedString("PrintPreview_Tool_Snapshot_Tool", "快照工具(&S)");
            rc.SetCustomizedString("PrintPreview_Tool_View", "视图(&V)");
            rc.SetCustomizedString("PrintPreview_Tool_Whole_Page", "合适页");
            rc.SetCustomizedString("PrintPreview_Tool_Zoom", "缩放(&Z)");
            rc.SetCustomizedString("PrintPreview_Tool_Zoom_In", "放大");

            rc.SetCustomizedString("PrintPreview_Tool_Zoom_Out", "缩小");

            rc.SetCustomizedString("PrintPreview_ToolCategory_Context_Menus", "上下文菜单");
            rc.SetCustomizedString("PrintPreview_ToolCategory_File", "文件");
            rc.SetCustomizedString("PrintPreview_ToolCategory_Menus", "菜单");
            rc.SetCustomizedString("PrintPreview_ToolCategory_Tools", "工具栏");
            rc.SetCustomizedString("PrintPreview_ToolCategory_View", "视图");
            rc.SetCustomizedString("PrintPreview_ToolCategory_Zoom_Mode", "缩放模式");

            rc.SetCustomizedString("PrintPreview_ToolTip_ClosePreview", "关闭");
            rc.SetCustomizedString("PrintPreview_ToolTip_Zoom", "缩放");
            rc.SetCustomizedString("StatusBar_Page_X_OF_X", "页:{0}/{1}");

            rc.SetCustomizedString("CustomizeImg_ToolBar_MenuBar", "菜单");
            rc.SetCustomizedString("CustomizeImg_ToolBar_Standard", "标准");
            rc.SetCustomizedString("CustomizeImg_ToolBar_View", "视图");
            rc.SetCustomizedString("PrintPreview_Tool_File", "文件(&F)");
            rc.SetCustomizedString("PrintPreview_Tool_Tools", "工具(&T)");
            rc.SetCustomizedString("PrintPreview_Tool_Dynamic_Zoom_Tool", "动态缩放工具(&D)");
            rc.SetCustomizedString("PrintPreview_Tool_Zoom_Out_Tool", "缩小工具");
            rc.SetCustomizedString("PrintPreview_Tool_Zoom_In_Tool", "放大工具");
            // rc.SetCustomizedString("PrintPreview_Tool_Page_Layout","菜单");
            rc.SetCustomizedString("PreviewRowColSelection_Cancel", "取消");
            rc.SetCustomizedString("PreviewRowColSelection_SelectedPages", "{0} x {1} 页");

            rc.SetCustomizedString("PreviewRowColSelection_Cancel", "取消");
            rc.SetCustomizedString("PrintPreview_Tool_Page_Width", "页宽");
            rc.SetCustomizedString("PrintPreview_ZoomListItem_MarginWidth", "文字宽度");
            rc.SetCustomizedString("PrintPreview_ZoomListItem_PageWidth", "页宽");
            rc.SetCustomizedString("PrintPreview_ZoomListItem_WholePage", "合适页");
            rc.SetCustomizedString("PrintPreview_Tool_Page_Layout", "页面布局");
            rc.SetCustomizedString("PrintPreview_Tool_Margin_Width", "文字宽度");
            rc.SetCustomizedString("ContextMenuPreviewHand", "缩放视图");


            rc.SetCustomizedString("PrintPreview_Tool_Reduce_Page_Thumbnails", "缩小");
            rc.SetCustomizedString("PrintPreview_Tool_Show_Page_Numbers", "显示页号");
            rc.SetCustomizedString("PrintPreview_Tool_ContextMenuThumbnail", "缩略图");
            rc.SetCustomizedString("PrintPreview_Tool_Enlarge_Page_Thumbnails", "放大");
            rc.SetCustomizedString("PrintPreview_Tool_Thumbnails", "缩略图");
            rc.SetCustomizedString("PrintPreview_Tool_Continuous", "连续排序");
            //说明
            rc.SetCustomizedString("StatusBar_DynamicZoom_Instructions", "单击并拖动进行缩放操作");
            rc.SetCustomizedString("StatusBar_Page_X_OF_X", "当前页: {0} / {1}");
            rc.SetCustomizedString("StatusBar_SnapShot_Instructions", "单击并拖动,系统将选定矩型区域复制到剪帖板");
            rc.SetCustomizedString("StatusBar_ZoomIn_Instructions", "单击并拖动,系统将放大选定矩型区域");
            rc.SetCustomizedString("StatusBar_ZoomOut_Instructions", "单击并拖动,系统将缩小选定矩型区域");
            rc.SetCustomizedString("StatusBar_Hand_Instructions", "单击并拖动以便显示更多内容");
        }
        private void InitCombox()
        {
            DataSet ds = m_bllBYDepartTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxDep.DataSource = ds.Tables[0];
                this.comboBoxDep.DisplayMember = "部门名称";
                this.comboBoxDep.ValueMember = "BYDepartTabID";
                this.comboBoxDep.SelectedIndex = 0;
            }
        }
        private void Frm_DepMonthOutPutRecvAndPay_Load(object sender, EventArgs e)
        {
            LocalPrintPreveiw();
            InitUltraWinGridSetting();
            InitCombox();
        }

        /// 取得某月的第一天
        /// </summary>
        /// <param name="datetime">要取得月份第一天的时间</param>
        /// <returns></returns>
        private DateTime FirstDayOfMonth(DateTime datetime)
        {
            return datetime.AddDays(1 - datetime.Day);
        }
        /// <summary>
        /// 取得某月的最后一天
        /// </summary>
        /// <param name="datetime">要取得月份最后一天的时间</param>
        /// <returns></returns>
        private DateTime LastDayOfMonth(DateTime datetime)
        {
            return datetime.AddDays(1 - datetime.Day).AddMonths(1).AddDays(-1);
        }
        private void MakeColumn(DataTable dt)
        {
            dt.Columns.Add("工厂简称", System.Type.GetType("System.String"));
            dt.Columns.Add("订单号", System.Type.GetType("System.String"));
            dt.Columns.Add("合同号", System.Type.GetType("System.String"));
            dt.Columns.Add("柜号", System.Type.GetType("System.String"));
            dt.Columns.Add("柜数", System.Type.GetType("System.Int32"));

            dt.Columns.Add("百业收据", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("百业装卸发票", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("运输发票", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("应收费用合计", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("应付费用", System.Type.GetType("System.Decimal"));

            dt.Columns.Add("商检金额", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("应付商检费", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("应收商检费", System.Type.GetType("System.Decimal"));

            DataSet ds = m_bllFeeTab.GetFeeNameList("FeeCateTab.FeeCateName like " + "'%" + "商检" + "%'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string strTemp = ds.Tables[0].Rows[i]["FeeName"].ToString();
                    dt.Columns.Add(strTemp, System.Type.GetType("System.Decimal"));
                }
            }

            dt.Columns.Add("应收商检费合计", System.Type.GetType("System.Decimal"));


            dt.Columns.Add("运输公司", System.Type.GetType("System.String"));
            dt.Columns.Add("应付运输费", System.Type.GetType("System.Decimal"));
            ds = m_bllFeeTab.GetFeeNameList("FeeCateTab.FeeCateName like " + "'%" + "运输" + "%'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string strTemp = ds.Tables[0].Rows[i]["FeeName"].ToString();
                    dt.Columns.Add(strTemp, System.Type.GetType("System.Decimal"));
                }
            }
            dt.Columns.Add("应收运输费合计", System.Type.GetType("System.Decimal"));


            dt.Columns.Add("报关行", System.Type.GetType("System.String"));
            dt.Columns.Add("报关单号", System.Type.GetType("System.String"));
            dt.Columns.Add("核销单号", System.Type.GetType("System.String"));
            dt.Columns.Add("报关金额", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("币种", System.Type.GetType("System.String"));
            dt.Columns.Add("经营单位", System.Type.GetType("System.String"));
            dt.Columns.Add("申报日期", System.Type.GetType("System.DateTime"));
            dt.Columns.Add("应付报关费", System.Type.GetType("System.Decimal"));

            ds = m_bllFeeTab.GetFeeNameList("FeeCateTab.FeeCateName like " + "'%" + "报关" + "%'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string strTemp = ds.Tables[0].Rows[i]["FeeName"].ToString();
                    dt.Columns.Add(strTemp, System.Type.GetType("System.Decimal"));
                }
            }
            dt.Columns.Add("应收报关费合计", System.Type.GetType("System.Decimal"));

            dt.Columns.Add("公帐汇款船务费", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("私帐汇款船务费", System.Type.GetType("System.Decimal"));

            ds = m_bllFeeTab.GetFeeNameList("FeeCateTab.FeeCateName like " + "'%" + "单证" + "%'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string strTemp = ds.Tables[0].Rows[i]["FeeName"].ToString();
                    dt.Columns.Add(strTemp, System.Type.GetType("System.Decimal"));
                }
            }

            dt.Columns.Add("应收单证费用合计", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("应付单证费用合计", System.Type.GetType("System.Decimal"));

            ds = m_bllFeeTab.GetFeeNameList("FeeCateTab.FeeCateName like " + "'%" + "其他" + "%'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string strTemp = ds.Tables[0].Rows[i]["FeeName"].ToString();
                    dt.Columns.Add(strTemp, System.Type.GetType("System.Decimal"));
                }
            }

            dt.Columns.Add("应收其他费用合计", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("应付其他费用合计", System.Type.GetType("System.Decimal"));
        }
       

        private void FillDataTable(DataTable dtNew,DataSet ds)
        {
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = dtNew.NewRow();
                    int nBGDComeBackTabID = Convert.ToInt32(ds.Tables[0].Rows[i]["BGDComeBackTabID"].ToString(), 10);
                    DataSet ds2 = m_bllCargoBoxTab.GetAllCargoBoxInfo("CargoBoxTab.BGDComeBackTabID = " + nBGDComeBackTabID.ToString());
                    if (ds2.Tables.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                    {
                        dr["柜数"] = ds2.Tables[0].Rows.Count;
                        StringBuilder strSql = new StringBuilder();
                        for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)
                        {
                            strSql.Append(ds2.Tables[0].Rows[j]["集装箱号"].ToString());
                            strSql.Append("\n");
                        }
                        dr["柜号"] = strSql.ToString();
                    }
                    else
                    {
                        dr["柜数"] = 0;
                        dr["柜号"] = "";
                    }


                    dr["合同号"] = ds.Tables[0].Rows[i]["合同编号"];
                    dr["商检金额"] = ds.Tables[0].Rows[i]["商检金额"];
                    dr["应付商检费"] = ds.Tables[0].Rows[i]["应付商检金额"];
                    dr["应收商检费"] = ds.Tables[0].Rows[i]["应收商检金额"];

                    dr["经营单位"] = ds.Tables[0].Rows[i]["经营单位"];
                    dr["订单号"] = ds.Tables[0].Rows[i]["订单号"];
                    dr["工厂简称"] = ds.Tables[0].Rows[i]["工厂名称"];
                    dr["报关行"] = ds.Tables[0].Rows[i]["报关行名称"];
                    dr["报关单号"] = ds.Tables[0].Rows[i]["报关单号"];
                    dr["核销单号"] = ds.Tables[0].Rows[i]["核销单号"];
                    dr["币种"] = ds.Tables[0].Rows[i]["币种"];
                    dr["申报日期"] = ds.Tables[0].Rows[i]["申报日期"];

                    dr["报关金额"] = ds.Tables[0].Rows[i]["报关金额"];
                    dr["运输公司"] = ds.Tables[0].Rows[i]["运输公司"];
                    dr["经营单位"] = ds.Tables[0].Rows[i]["单证公司"];
                    dr["公帐汇款船务费"] = ds.Tables[0].Rows[i]["公帐汇款船务费"];
                    dr["私帐汇款船务费"] = ds.Tables[0].Rows[i]["私帐汇款船务费"];
                    dr["运输公司"] = ds.Tables[0].Rows[i]["运输公司"];
                    dr["应付运输费"] = ds.Tables[0].Rows[i]["应付运输费"];

                    dr["应付报关费"] = ds.Tables[0].Rows[i]["应付报关费"];
                    dr["应付单证费用合计"] = ds.Tables[0].Rows[i]["应付单证费"];
                    dr["应付其他费用合计"] = ds.Tables[0].Rows[i]["应付其他费"];

                    int nSelectFacFeeTabID = Convert.ToInt32(ds.Tables[0].Rows[i]["FacFeeTabID"].ToString(), 10);
                    DataSet ds3 = m_bllFacFeeRelationTab.GetFeeNameList("FacFeeTabID = " + nSelectFacFeeTabID.ToString() + " and FeeCateTab.FeeCateName like " + "'%" + "商检" + "%'");

                    if (ds3.Tables.Count > 0 && ds3.Tables[0].Rows.Count > 0)
                    {
                        Decimal dtTotalTemp = 0;
                        for (int k = 0; k < ds3.Tables[0].Rows.Count; k++)
                        {
                            string strTemp = ds3.Tables[0].Rows[k]["费用名称"].ToString();
                            dr[strTemp] = ds3.Tables[0].Rows[k]["费用金额"].ToString();
                            dtTotalTemp += Convert.ToDecimal(ds3.Tables[0].Rows[k]["费用金额"].ToString());

                        }

                        dr["应收商检费合计"] = (Decimal)dr["应收商检费"] + dtTotalTemp;
                    }

                    ds3 = m_bllFacFeeRelationTab.GetFeeNameList("FacFeeTabID = " + nSelectFacFeeTabID.ToString() + " and FeeCateTab.FeeCateName like " + "'%" + "运输" + "%'");

                    if (ds3.Tables.Count > 0 && ds3.Tables[0].Rows.Count > 0)
                    {
                        Decimal dtTotalTemp = 0;
                        for (int k = 0; k < ds3.Tables[0].Rows.Count; k++)
                        {
                            string strTemp = ds3.Tables[0].Rows[k]["费用名称"].ToString();
                            dr[strTemp] = ds3.Tables[0].Rows[k]["费用金额"].ToString();
                            dtTotalTemp += Convert.ToDecimal(ds3.Tables[0].Rows[k]["费用金额"].ToString());

                        }

                        dr["应收运输费合计"] = dtTotalTemp;
                    }

                    ds3 = m_bllFacFeeRelationTab.GetFeeNameList("FacFeeTabID = " + nSelectFacFeeTabID.ToString() + " and FeeCateTab.FeeCateName like " + "'%" + "报关" + "%'");

                    if (ds3.Tables.Count > 0 && ds3.Tables[0].Rows.Count > 0)
                    {
                        Decimal dtTotalTemp = 0;
                        for (int k = 0; k < ds3.Tables[0].Rows.Count; k++)
                        {
                            string strTemp = ds3.Tables[0].Rows[k]["费用名称"].ToString();
                            dr[strTemp] = ds3.Tables[0].Rows[k]["费用金额"].ToString();
                            dtTotalTemp += Convert.ToDecimal(ds3.Tables[0].Rows[k]["费用金额"].ToString());

                        }

                        dr["应收报关费合计"] = dtTotalTemp;
                    }
                    ds3 = m_bllFacFeeRelationTab.GetFeeNameList("FacFeeTabID = " + nSelectFacFeeTabID.ToString() + " and FeeCateTab.FeeCateName like " + "'%" + "单证" + "%'");

                    if (ds3.Tables.Count > 0 && ds3.Tables[0].Rows.Count > 0)
                    {
                        Decimal dtTotalTemp = 0;
                        for (int k = 0; k < ds3.Tables[0].Rows.Count; k++)
                        {
                            string strTemp = ds3.Tables[0].Rows[k]["费用名称"].ToString();
                            dr[strTemp] = ds3.Tables[0].Rows[k]["费用金额"].ToString();
                            dtTotalTemp += Convert.ToDecimal(ds3.Tables[0].Rows[k]["费用金额"].ToString());

                        }

                        dr["应收单证费用合计"] = dtTotalTemp;
                    }

                    ds3 = m_bllFacFeeRelationTab.GetFeeNameList("FacFeeTabID = " + nSelectFacFeeTabID.ToString() + " and FeeCateTab.FeeCateName like " + "'%" + "其他" + "%'");

                    if (ds3.Tables.Count > 0 && ds3.Tables[0].Rows.Count > 0)
                    {
                        Decimal dtTotalTemp = 0;
                        for (int k = 0; k < ds3.Tables[0].Rows.Count; k++)
                        {
                            string strTemp = ds3.Tables[0].Rows[k]["费用名称"].ToString();
                            dr[strTemp] = ds3.Tables[0].Rows[k]["费用金额"].ToString();
                            dtTotalTemp += Convert.ToDecimal(ds3.Tables[0].Rows[k]["费用金额"].ToString());

                        }

                        dr["应收其他费用合计"] = dtTotalTemp;
                    }

                    dr["百业收据"] = (Decimal)dr["应收单证费用合计"] + (Decimal)dr["应收其他费用合计"] + (Decimal)dr["私帐汇款船务费"];
                    dr["百业装卸发票"] = (Decimal)dr["应收商检费合计"] + (Decimal)dr["应收报关费合计"] + (Decimal)dr["公帐汇款船务费"];
                    dr["运输发票"] = dr["应收运输费合计"];
                    dr["应收费用合计"] = (Decimal)dr["百业收据"] + (Decimal)dr["百业装卸发票"] + (Decimal)dr["运输发票"];
                    dr["应付费用"] = (Decimal)dr["应付商检费"] + (Decimal)dr["应付运输费"] + (Decimal)dr["应付报关费"]
                        + (Decimal)dr["应付单证费用合计"] + (Decimal)dr["应付其他费用合计"]
                        + (Decimal)dr["私帐汇款船务费"] + (Decimal)dr["公帐汇款船务费"];

                    dtNew.Rows.Add(dr.ItemArray);
                }
            }
        }

        private void buttonImport_Click(object sender, EventArgs e)
        {
            ultraGrid1.DataSource = null;
            DateTime dtFirst = FirstDayOfMonth(this.dateTimePickerDate.Value);
            DateTime dtEnd = LastDayOfMonth(this.dateTimePickerDate.Value);
            DataSet ds = m_bllFacFeeTab.ShowRecvFacFeeRecEx(@"BYDepartTab.DepartName = '" + this.comboBoxDep.Text + "'"
                                     + " and BGDComeBackTab.SBDate >= '" + dtFirst.Date + "'"
                                     + " and BGDComeBackTab.SBDate <= '" + dtEnd.Date + "'");

            //Fee_HelpClass fhc = new Fee_HelpClass();
            DataTable dtNew = new DataTable();

            Fee_HelpClass.MakeColumn(dtNew);
            Fee_HelpClass.FillDataTable(dtNew, ds, null);

            ultraGrid1.DataSource = dtNew;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["柜号"].CellMultiLine = Infragistics.Win.DefaultableBoolean.True;
            ProcessMultiHeader();
        }

        private void ProcessMultiHeader()
        {
            UltraGridColumn m_ultraGridColumnBasicInfo = null;
            UltraGridColumn m_ultraGridColumnKaipiaoInfo = null;
            UltraGridColumn m_ultraGridColumnSJInfo = null;
            UltraGridColumn m_ultraGridColumnTransInfo = null;
            UltraGridColumn m_ultraGridColumnBGInfo = null;
            UltraGridColumn m_ultraGridColumnShipInfo = null;
            UltraGridColumn m_ultraGridColumnDZInfo = null;
            UltraGridColumn m_ultraGridColumnOtherInfo = null;

            foreach (UltraGridColumn column2 in this.ultraGrid1.DisplayLayout.Bands[0].Columns)
            {
                column2.RowLayoutColumnInfo.OriginY = 2;
            }
            int nSpanX = 5 * 2;
            int nOriginX = 0;
            m_ultraGridColumnBasicInfo = ultraGrid1.DisplayLayout.Bands[0].Columns.Add("基本资料", "基本资料");
            m_ultraGridColumnBasicInfo.CellActivation = Activation.Disabled;
            m_ultraGridColumnBasicInfo.SortIndicator = SortIndicator.Disabled;
            m_ultraGridColumnBasicInfo.RowLayoutColumnInfo.PreferredCellSize = new Size(1, 1);
            m_ultraGridColumnBasicInfo.RowLayoutColumnInfo.AllowLabelSizing = RowLayoutSizing.None;
            m_ultraGridColumnBasicInfo.RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly;
            m_ultraGridColumnBasicInfo.RowLayoutColumnInfo.OriginX = nOriginX;//有2个列隐藏了
            m_ultraGridColumnBasicInfo.RowLayoutColumnInfo.OriginY = 0;
            m_ultraGridColumnBasicInfo.RowLayoutColumnInfo.SpanX = nSpanX;
            m_ultraGridColumnBasicInfo.RowLayoutColumnInfo.SpanY = 2;

            nOriginX = nOriginX + nSpanX;
            nSpanX = 4 * 2;
            m_ultraGridColumnKaipiaoInfo = ultraGrid1.DisplayLayout.Bands[0].Columns.Add("开票明细类别", "开票明细类别");
            m_ultraGridColumnKaipiaoInfo.CellActivation = Activation.Disabled;
            m_ultraGridColumnKaipiaoInfo.SortIndicator = SortIndicator.Disabled;
            m_ultraGridColumnKaipiaoInfo.RowLayoutColumnInfo.PreferredCellSize = new Size(1, 1);
            m_ultraGridColumnKaipiaoInfo.RowLayoutColumnInfo.AllowLabelSizing = RowLayoutSizing.None;
            m_ultraGridColumnKaipiaoInfo.RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly;
            m_ultraGridColumnKaipiaoInfo.RowLayoutColumnInfo.OriginX = nOriginX;//有2个列隐藏了
            m_ultraGridColumnKaipiaoInfo.RowLayoutColumnInfo.OriginY = 0;
            m_ultraGridColumnKaipiaoInfo.RowLayoutColumnInfo.SpanX = nSpanX;
            m_ultraGridColumnKaipiaoInfo.RowLayoutColumnInfo.SpanY = 2;


            DataSet ds = m_bllFeeTab.GetFeeNameList("FeeCateTab.FeeCateName like " + "'%" + "商检" + "%'");
            
            nOriginX = nOriginX + nSpanX + 2;
            nSpanX = ds.Tables[0].Rows.Count * 2 + 4 * 2;
            m_ultraGridColumnSJInfo = ultraGrid1.DisplayLayout.Bands[0].Columns.Add("商检", "商检");
            m_ultraGridColumnSJInfo.CellActivation = Activation.Disabled;
            m_ultraGridColumnSJInfo.SortIndicator = SortIndicator.Disabled;
            m_ultraGridColumnSJInfo.RowLayoutColumnInfo.PreferredCellSize = new Size(1, 1);
            m_ultraGridColumnSJInfo.RowLayoutColumnInfo.AllowLabelSizing = RowLayoutSizing.None;
            m_ultraGridColumnSJInfo.RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly;
            m_ultraGridColumnSJInfo.RowLayoutColumnInfo.OriginX = nOriginX;//有2个列隐藏了
            m_ultraGridColumnSJInfo.RowLayoutColumnInfo.OriginY = 0;
            m_ultraGridColumnSJInfo.RowLayoutColumnInfo.SpanX = nSpanX;
            m_ultraGridColumnSJInfo.RowLayoutColumnInfo.SpanY = 2;


            ds = m_bllFeeTab.GetFeeNameList("FeeCateTab.FeeCateName like " + "'%" + "运输" + "%'");

            nOriginX = nOriginX + nSpanX;
            nSpanX = ds.Tables[0].Rows.Count * 2 + 3 * 2;
            m_ultraGridColumnTransInfo = ultraGrid1.DisplayLayout.Bands[0].Columns.Add("运输", "运输");
            m_ultraGridColumnTransInfo.CellActivation = Activation.Disabled;
            m_ultraGridColumnTransInfo.SortIndicator = SortIndicator.Disabled;
            m_ultraGridColumnTransInfo.RowLayoutColumnInfo.PreferredCellSize = new Size(1, 1);
            m_ultraGridColumnTransInfo.RowLayoutColumnInfo.AllowLabelSizing = RowLayoutSizing.None;
            m_ultraGridColumnTransInfo.RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly;
            m_ultraGridColumnTransInfo.RowLayoutColumnInfo.OriginX = nOriginX;//有2个列隐藏了
            m_ultraGridColumnTransInfo.RowLayoutColumnInfo.OriginY = 0;
            m_ultraGridColumnTransInfo.RowLayoutColumnInfo.SpanX = nSpanX;
            m_ultraGridColumnTransInfo.RowLayoutColumnInfo.SpanY = 2;


            ds = m_bllFeeTab.GetFeeNameList("FeeCateTab.FeeCateName like " + "'%" + "报关" + "%'");
            nOriginX = nOriginX + nSpanX;
            nSpanX = ds.Tables[0].Rows.Count * 2 + 9 * 2;
            m_ultraGridColumnBGInfo = ultraGrid1.DisplayLayout.Bands[0].Columns.Add("报关", "报关");
            m_ultraGridColumnBGInfo.CellActivation = Activation.Disabled;
            m_ultraGridColumnBGInfo.SortIndicator = SortIndicator.Disabled;
            m_ultraGridColumnBGInfo.RowLayoutColumnInfo.PreferredCellSize = new Size(1, 1);
            m_ultraGridColumnBGInfo.RowLayoutColumnInfo.AllowLabelSizing = RowLayoutSizing.None;
            m_ultraGridColumnBGInfo.RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly;
            m_ultraGridColumnBGInfo.RowLayoutColumnInfo.OriginX = nOriginX;//有2个列隐藏了
            m_ultraGridColumnBGInfo.RowLayoutColumnInfo.OriginY = 0;
            m_ultraGridColumnBGInfo.RowLayoutColumnInfo.SpanX = nSpanX;
            m_ultraGridColumnBGInfo.RowLayoutColumnInfo.SpanY = 2;

            nOriginX = nOriginX + nSpanX;
            nSpanX = 2 * 2;
            m_ultraGridColumnShipInfo = ultraGrid1.DisplayLayout.Bands[0].Columns.Add("船务", "船务");
            m_ultraGridColumnShipInfo.CellActivation = Activation.Disabled;
            m_ultraGridColumnShipInfo.SortIndicator = SortIndicator.Disabled;
            m_ultraGridColumnShipInfo.RowLayoutColumnInfo.PreferredCellSize = new Size(1, 1);
            m_ultraGridColumnShipInfo.RowLayoutColumnInfo.AllowLabelSizing = RowLayoutSizing.None;
            m_ultraGridColumnShipInfo.RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly;
            m_ultraGridColumnShipInfo.RowLayoutColumnInfo.OriginX = nOriginX;//有2个列隐藏了
            m_ultraGridColumnShipInfo.RowLayoutColumnInfo.OriginY = 0;
            m_ultraGridColumnShipInfo.RowLayoutColumnInfo.SpanX = nSpanX;
            m_ultraGridColumnShipInfo.RowLayoutColumnInfo.SpanY = 2;

            ds = m_bllFeeTab.GetFeeNameList("FeeCateTab.FeeCateName like " + "'%" + "单证" + "%'");

            nOriginX = nOriginX + nSpanX;
            nSpanX = ds.Tables[0].Rows.Count * 2 + 2 * 2;
            m_ultraGridColumnDZInfo = ultraGrid1.DisplayLayout.Bands[0].Columns.Add("单证", "单证");
            m_ultraGridColumnDZInfo.CellActivation = Activation.Disabled;
            m_ultraGridColumnDZInfo.SortIndicator = SortIndicator.Disabled;
            m_ultraGridColumnDZInfo.RowLayoutColumnInfo.PreferredCellSize = new Size(1, 1);
            m_ultraGridColumnDZInfo.RowLayoutColumnInfo.AllowLabelSizing = RowLayoutSizing.None;
            m_ultraGridColumnDZInfo.RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly;
            m_ultraGridColumnDZInfo.RowLayoutColumnInfo.OriginX = nOriginX;//有2个列隐藏了
            m_ultraGridColumnDZInfo.RowLayoutColumnInfo.OriginY = 0;
            m_ultraGridColumnDZInfo.RowLayoutColumnInfo.SpanX = nSpanX;
            m_ultraGridColumnDZInfo.RowLayoutColumnInfo.SpanY = 2;

            ds = m_bllFeeTab.GetFeeNameList("FeeCateTab.FeeCateName like " + "'%" + "其他" + "%'");
            nOriginX = nOriginX + nSpanX;
            nSpanX = ds.Tables[0].Rows.Count * 2 + 2 * 2;
            m_ultraGridColumnOtherInfo = ultraGrid1.DisplayLayout.Bands[0].Columns.Add("其他", "其他");
            m_ultraGridColumnOtherInfo.CellActivation = Activation.Disabled;
            m_ultraGridColumnOtherInfo.SortIndicator = SortIndicator.Disabled;
            m_ultraGridColumnOtherInfo.RowLayoutColumnInfo.PreferredCellSize = new Size(1, 1);
            m_ultraGridColumnOtherInfo.RowLayoutColumnInfo.AllowLabelSizing = RowLayoutSizing.None;
            m_ultraGridColumnOtherInfo.RowLayoutColumnInfo.LabelPosition = LabelPosition.LabelOnly;
            m_ultraGridColumnOtherInfo.RowLayoutColumnInfo.OriginX = nOriginX;//有2个列隐藏了
            m_ultraGridColumnOtherInfo.RowLayoutColumnInfo.OriginY = 0;
            m_ultraGridColumnOtherInfo.RowLayoutColumnInfo.SpanX = nSpanX;
            m_ultraGridColumnOtherInfo.RowLayoutColumnInfo.SpanY = 2;
        }

        private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            ultraGrid1.DisplayLayout.Bands[0].UseRowLayout = true;
            ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
            foreach (UltraGridColumn ugc in ultraGrid1.DisplayLayout.Bands[0].Columns)
                ugc.PerformAutoResize();
        }

        private void buttonExportToExcel_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
        }

        private void buttonPrint_Click(object sender, EventArgs e)
        {
            this.ultraGridPrintDocument1.Grid = this.ultraGrid1;
            this.ultraPrintPreviewDialog1.Document = this.ultraGridPrintDocument1;
            this.ultraPrintPreviewDialog1.ShowDialog(this);
        }
    }
}
